package com.chezhujie.www.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import com.chezhujie.www.domain.vo.Coupons;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chezhujie.www.core.page.Pagination;
import com.chezhujie.www.domain.Czjawardstock;
import com.chezhujie.www.domain.Czjbranch;
import com.chezhujie.www.domain.vo.CzjawardstockVO;
import com.chezhujie.www.persistence.CzjawardstockMapper;
import com.chezhujie.www.utils.UUIDUtils;


@Service("czjawardstockService")
public class CzjawardstockService {
	@Autowired
	private CzjawardstockMapper czjawardstockMapper;

	/**
	 * 查询某个czj_awardstock 奖品库
	 * @param param
	 * @return
	 */
	public Czjawardstock getCzjawardstock(Map<String,Object> param) {
		return czjawardstockMapper.getCzjawardstock(param);
	}
	
	/**
	 * 查询某个czj_awardstock 奖品库
	 * @param param
	 * @return
	 */
	public CzjawardstockVO getCzjawardstockVO(Map<String,Object> param) {
		return czjawardstockMapper.getCzjawardstockVO(param);
	}	
	
	/**
	 * 查询某个czj_awardstock 奖品库
	 * @param param
	 * @return
	 */
	public Czjbranch getCzjbranch(Map<String,Object> param) {
		return czjawardstockMapper.getCzjbranch(param);
	}
   
	/**
	 * 查询这个奖品的所有数量的
	 * @param param
	 * @return
	 */
	public List<Czjbranch> getCzjbranchByCzjawardstockId(Map<String,Object> param) {
		return czjawardstockMapper.getCzjbranchByCzjawardstockId(param);
	}	
	
	/**
	 * 查询czj_awardstock 奖品库列表
	 * @return
	 */
	public Map<String,Object> getCzjawardstockList(Map<String,Object> param) {
		Map<String,Object> returnMap = new HashMap<String,Object>();
		returnMap.put("totalCounts", czjawardstockMapper.getTotalRows(param));
		returnMap.put("list", czjawardstockMapper.getCzjawardstockList(param));
		return returnMap;
	}

   
	/**
	 * 查询czj_awardstock 奖品库列表
	 * @return
	 */
	public  Pagination getCzjawardstockList(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=czjawardstockMapper.getTotalRows(param);
		List<Czjawardstock> list=	czjawardstockMapper.getCzjawardstockList(param);
	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}
	
	/**
	 * 查询czj_awardstock 奖品库列表
	 * @return
	 */
	public  List<Czjawardstock>  getCzjawardstockListALL(Map<String,Object> param) {
		List<Czjawardstock> list=	czjawardstockMapper.getCzjawardstockListALL(param);	
		return list;
		
	}	
	
    
	/**
	 * 新增czj_awardstock 奖品库
	 * @param czjawardstock
	 * @param param
	 */
	@Transactional
	public void insertCzjawardstock(Czjawardstock czjawardstock) {
		czjawardstock.setAwardstockId(UUIDUtils.getUUID());
		czjawardstock.setChouqunum(0);
		czjawardstockMapper.insertCzjawardstock(czjawardstock);
	}
   
	/**
	 * 新增 分配表
	 * @param czjawardstock
	 * @param param
	 */
	@Transactional
	public void insertCzjbranch(Czjbranch czjbranch) {
		czjbranch.setBranchId(UUIDUtils.getUUID());
		czjawardstockMapper.insertCzjbranch(czjbranch);
	}	
	
	/**
	 * 编辑czj_awardstock 奖品库
	 * @param czjawardstock
	 * @param param
	 */
	@Transactional
	public void updateCzjawardstock(Czjawardstock czjawardstock) {
		czjawardstockMapper.updateCzjawardstock(czjawardstock);
	}
   
	/**
	 * 编辑czj_awardstock 奖品库
	 * @param czjawardstock
	 * @param param
	 */
	@Transactional
	public void updateCzjbranch(Czjbranch czjbranch ) {
		czjawardstockMapper.updateCzjbranch(czjbranch);
	}	
	
	/**
	 * 删除czj_awardstock 奖品库
	 * @param param
	 */    
	@Transactional
	public void deleteCzjawardstock(List<String> awardstockIdList) {
		for(String awardstockId: awardstockIdList){
	  		Map<String,Object> param = new HashMap<String,Object>();
	  		param.put("awardstockId", awardstockId);
	 	   czjawardstockMapper.deleteCzjawardstock(param);	  		
		}
	}

	/**
	 * 删除czj_branch 分配库
	 * @param param
	 */    
	@Transactional
	public void deleteCzjbranch(Map<String,Object> param) {
	 	   czjawardstockMapper.deleteCzjbranch(param);	  				
	}

	public List<Map<String, Object>> getAwardstockByBusin(Map<String, Object> map) {
		return czjawardstockMapper.getAwardstockByBusin(map);		
	}

	public List<Czjawardstock> queryCatByCid(String commodityId) {
		return czjawardstockMapper.queryCatByCid(commodityId);
	}	

	public List<Czjawardstock> getListResult(Map<String,Object> param){
		return czjawardstockMapper.getCzjawardstockList(param);
	}

    public Czjawardstock queryById(String couponsId) {
		return czjawardstockMapper.queryById(couponsId);
    }

	public Coupons queryMapById(String couponsId) {
		return czjawardstockMapper.queryMapById(couponsId);
	}

	/** 获取该商品优惠券列表
	 * @param params*/
    public List<Coupons> queryCouponsBy(Map<String, Object> params)  {
		return czjawardstockMapper.queryCouponsBy(params);
	}

	/**
	 * 得到活动优惠券信息
	 * @param id
	 * @return
	 */
	public Map<String,Object> getActCoupons(String id) {
		return czjawardstockMapper.getActCoupons(id);
	}

	public Map<String,Object> getCommodityCoupons(String id) {
		return czjawardstockMapper.getCommodityCoupons(id);
	}

	public Map<String,Object> getGoods(String id)  {
		return czjawardstockMapper.getGoods(id);
	}

	public Map<String,Object> getRedpacket(String id)   {
		return czjawardstockMapper.getRedpacket(id);
	}

	public Map<String,Object> getPlaces(String id)   {
		return czjawardstockMapper.getPlaces(id);
	}

    public List<Map<String,Object>> getListAwardId(Map<String, Object> param)   {
		return czjawardstockMapper.getListAwardId(param);
	}

	public List<Czjawardstock> queryByAwardonIds(List<String> listIds) {
		if(listIds!=null&&listIds.size()!=0){
			return czjawardstockMapper.queryByAwardonIds(listIds);
		}
		return new ArrayList<Czjawardstock>();
	}

    public List<Czjawardstock> queryAll() {
		return czjawardstockMapper.queryAll();
    }

    public Czjawardstock queryByAwardstockId(String awardstockId) {
		return czjawardstockMapper.queryByAwardstockId(awardstockId);
	}
}